# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Mario Finelli <mario dot finelli at yahoo dot com>
# Contributor: Andy Weidenbaum <archbaum at gmail dot com>
# Contributor: Peter Wu <lekensteyn at gmail dot com>

pkgname=babel-cli
pkgver=7.21.0
pkgrel=1
pkgdesc="A compiler for writing next generation JavaScript"
arch=('any')
url="https://babeljs.io/"
license=('MIT')
depends=('nodejs' 'babel-core' 'semver')
makedepends=('npm')
provides=('nodejs-babel-cli')
conflicts=('nodejs-babel-cli' 'openbabel<3')
replaces=('nodejs-babel-cli')
source=("$pkgname-$pkgver.tgz::https://registry.npmjs.org/@babel/cli/-/cli-$pkgver.tgz"
        LICENSE)
noextract=($pkgname-$pkgver.tgz)
sha512sums=('c62ec2c724bc5e34b28b050609fc1ff9baed2718d6d7f6537015243f5d316b02045cb5f91f32e7fb7697920c68cdc3f6521461b4a4e642eaf0f5469eb3b8d9ac'
            'fc5471459770967e2632efb110b8370caa3424b7d87c1180f49605f7e6b1593746888b6c99c713c0c3046c5833c01c1a15bf3d549a343eaa077885bcc9f3d4e3')

package() {
  npm install -g --legacy-peer-deps --prefix "$pkgdir"/usr "$srcdir"/$pkgname-$pkgver.tgz
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm -r "$pkgdir"/usr/lib/node_modules/@babel/cli/node_modules/{,.bin/}semver

  # Non-deterministic race in npm gives 777 permissions to random directories.
  # See https://github.com/npm/npm/issues/9359 for details.
  chmod -R u=rwX,go=rX "$pkgdir"

  # npm installs package.json owned by build user
  # https://bugs.archlinux.org/task/63396
  chown -R root:root "$pkgdir"
}
